package adminlte.controller;

import adminlte.service.TableService;
import adminlte.vo.ResponseData;
import adminlte.vo.ResponseTableData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Random;

/**
 * @author ZHUFEIFEI
 */
@Slf4j
@RestController
@RequestMapping("table")
public class TableController {

    @Autowired
    private TableService tableService;

    @RequestMapping(value = "/data", method = {RequestMethod.GET, RequestMethod.POST})
    public ResponseTableData<Object> data(HttpServletRequest request) {
        request.getParameterMap().forEach((k, v) -> log.info("{} => {}", k, StringUtils.arrayToCommaDelimitedString(v)));
        return ResponseTableData.ok(300, 300, this.tableService.users());
    }

    @RequestMapping(value = "/update", method = {RequestMethod.POST})
    public ResponseData<Object> update(HttpServletRequest request) {
        request.getParameterMap().forEach((k, v) -> log.info("{} => {}", k, StringUtils.arrayToCommaDelimitedString(v)));
        return ResponseData.ok();
    }
}
